import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/knowledgeword.dart';
import 'package:ichinesereader/widgets/buttons/debouncedMaterialButton.dart';

import '../../themes/appTheme.dart';
// import 'package:ichinesereader/utils/log.dart';

// ignore: must_be_immutable
class NewOrEditWordFolderDialog extends GetView<KnowledgeWordsController> {
  NewOrEditWordFolderDialog({
    Key? key,
    required this.title,
    required this.message,
    required this.type,
  }) : super(key: key);

  String title;
  String message;
  String type;
  String parentFolderId = '';
  final folderNameController = TextEditingController();

  void _createFolder() async {
    controller.createKnowledgeWordFolder(
        parentFolderId, folderNameController.text);
  }

  void _editFolder() async {}

  @override
  Widget build(BuildContext context) {
    parentFolderId = controller.currdir.length > 0
        ? controller.currdir[controller.currdir.length - 1].toString()
        : '';
    return AlertDialog(
      title: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            this.title,
            style: TextStyle(
                fontSize: 30.0,
                decoration: TextDecoration.underline,
                decorationStyle: TextDecorationStyle.dotted),
          ),
          InkWell(
            onTap: () {
              Navigator.of(context).pop();
            },
            child: Icon(Icons.cancel,
                color: Get.isDarkMode ? Colors.white : Colors.blueGrey),
          ),
        ],
      ),
      titleTextStyle: TextStyle(
          letterSpacing: 1,
          color: Get.isDarkMode ? Get.theme.primaryColorDark : Colors.blueGrey,
          decoration: TextDecoration.underline,
          decorationStyle: TextDecorationStyle.dotted,
          fontSize: 21.0),
      backgroundColor:
          Get.isDarkMode ? AppTheme.colors.darkTheme2 : Colors.white,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(
          Radius.circular(6.0),
        ),
      ),
      content: Container(
        height: 300,
        width: 450,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Padding(
                  padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
                  child: Container(
                    width: 300,
                    child: TextField(
                      //style: TextStyle(color: Get.isDarkMode? Colors.white : Colors.black),
                      controller: folderNameController,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(6.0),
                        ),
                        //labelText: 'Create New Folder'.tr,
                        hintText: 'Folder Name'.tr,
                        hintStyle: TextStyle(
                          color: Get.isDarkMode
                              ? Get.theme.primaryColor
                              : Colors.grey[300],
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
            Center(
              child: Container(
                width: 210.0,
                height: 45.0,
                child: DebouncedMaterialButton(
                  color: Get.isDarkMode
                      ? (Colors.white)
                      : Theme.of(context).primaryColor,
                  textColor: Get.isDarkMode
                      ? (Colors.black)
                      : Theme.of(context).primaryColorLight,
                  onPressed: () {
                    if (type == 'edit') {
                      _editFolder();
                    } else {
                      _createFolder();
                    }
                    Navigator.of(context).pop();
                  },
                  child: Text(
                    'Submit'.tr,
                    style: TextStyle(fontSize: 18.0),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
